//
//  UIViewController+SetNavication.m
//  页面搭建5-18
//
//  Created by 蓝凌 on 17/5/18.
//  Copyright © 2017年 蓝凌. All rights reserved.
//

#import "UIViewController+SetNavication.h"
#import <objc/runtime.h>
@implementation UIViewController (SetNavication)

//设置导航控制器的标题  并自定义返回按钮
-(void)setRightNavigationTitle:(NSString * )title
{
    if (!title.length) {
        self.navigationItem.rightBarButtonItem = nil;
    }else{
        self.navigationItem.rightBarButtonItem = ({
            
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button addTarget:self action:@selector(RightBarAction) forControlEvents:(UIControlEventTouchUpInside)];
            CGFloat  width = [Factory sizeWithText:title withFont:[UIFont systemFontOfSize:16]].width;
            button.frame = CGRectMake(0, 0, width, 30);
            button.titleEdgeInsets = UIEdgeInsetsMake(0,0, 0,0);
            button.titleLabel.textAlignment = NSTextAlignmentRight;
            [button setTitle:title forState:(UIControlStateNormal)];
            [button setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)];
            button.titleLabel.font = [UIFont systemFontOfSize:16];
            UIBarButtonItem * BarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
            
            BarButtonItem;
        });
    }
    
    

    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

-(void)RightBarAction{
    
}

-(void)setLeftNavigationButton
{
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"黑色返回"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"黑色返回"] forState:UIControlStateHighlighted];
    leftBtn.frame = CGRectMake(0, 0, 50, 30);
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 25);
    [leftBtn addTarget:self action:@selector(LeftBarAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
    UIBarButtonItem *leftItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    leftItem1.width = -10;
    self.navigationItem.leftBarButtonItems = @[leftItem1 , leftItem];
    
}

-(void)LeftBarAction{
    
}

-(void)setLeftNavigationButtonWithTitle:(NSString *)title
{
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [leftBtn setTitle:title forState:(UIControlStateNormal)];
    [leftBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)];
    leftBtn.titleLabel.font = [Factory fitFont:14];
    
    [leftBtn setImage:[UIImage imageNamed:@"黑色返回"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"黑色返回"] forState:UIControlStateHighlighted];
    leftBtn.frame = CGRectMake(0, 0, 50, 30);
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
    UIBarButtonItem *leftItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    leftItem1.width = -10;
    self.navigationItem.leftBarButtonItems = @[leftItem1 , leftItem];
    
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}



@end
